---@class UIExpeditionStagePreview : UIBase
UIExpeditionStagePreview = UIBase.New(PanelResNames.UIExpeditionStagePreview)
local t = UIExpeditionStagePreview

function t.Init(stageId)
    t.stageId = stageId
    UIBase.Init(t)
end

function t:OnCreate()
    self.btnClose = self:GetChild("BgClose")
    self.monsterItemList = self:GetList("HeroList")
    self.rewardItemList = self:GetList("RewardList")
    self.btnStart = self:GetChild("btnStart")
    self.powerText = self:GetChild("PowerPreview")

    self:SetDynamicList(self.monsterItemList,self.MonsterItemRender,nil,true)
    self:SetDynamicList(self.rewardItemList,self.RewardItemRender)
    self:RegisterOnClick(self.btnClose,self.ClickClose)
    self:RegisterOnClick(self.btnStart,self.ClickStart)

end

function t:OnEnable()
    local info = ExpeditionMgr.GetStageInfo(t.stageId)
    self.monsterItemList.numItems = #info.formation
    self.powerText.text = getNumString(info.power)
    self.rewardOldDataList =  ExpeditionMgr.GetStageInfo(t.stageId).items
    self.rewardDataList = {};
    local power = logicMgr.EcoBuffManager.getEcoBuffByTypeAndItemId(Config.EcoBuffCondition.LongJourneySelectReward);
    local power2 = logicMgr.ExpeditionMgr.GetPassNum();
    for k, v in pairs(self.rewardOldDataList) do
        local power1 = logicMgr.EcoBuffManager.getEcoBuffByTypeAndItemId(Config.EcoBuffCondition.LongJourneySelectCost, v.itemModelId);
        local data = {};
        data["num"] = v.num * (1 + power + (power1 + power2) * 0.0001);
        data["itemModelId"] = v.itemModelId
        table.insert(self.rewardDataList,data);
    end
    self.rewardItemList.numItems = #self.rewardDataList
end
function t:OnDisable()
end
function t:OnDestroy()
end

function t:MonsterItemRender(index,go)
    local info = ExpeditionMgr.GetStageInfo(t.stageId)
    local formation = info.formation[index]
    local temp = {
        level = formation.level,
        icon = HeroManager.GetHeroIconByModelId(formation.modelId),
        quality = HeroManager.GetHeroQualityByModelId(formation.modelId),
        type = dataTable.getDataTableByStringId("t_hero",formation.modelId,"f_HeroType")
    }
    local item = CtrlManager.GetCtrl(PanelNames.HeadRectItem)
    item.initData( go,temp)
    item.UpdateHPMPBar(go,formation.hp,formation.energy)
    if formation.hp == 0 then
        go.grayed = true
    else
        go.grayed = false
    end
end
function t:RewardItemRender(index,go)
    local data = self.rewardDataList[index]
    local item = CtrlManager.GetCtrl(PanelNames.Item)
    --是否开启了双倍远征活动
    local isMultiple = false
    if not ActiveManager.IsActiveEnd(10301) then
        isMultiple = true
    end
    item.initData(go,data,nil,nil,nil,nil,nil,isMultiple)
end

function t:ClickStart()
    logicMgr.ExpeditionMgr.SetHeroDeadFlag()
    self:ClickClose()
    showUI(PanelNames.UIBattleTeam, EnumConst.FightTypeConst.Expedition, t.stageId, function(formations,enemy)
        logicMgr.ExpeditionMgr.ClearHeroDeadFlag()
        ExpeditionHandler.ReqExpeditionBoss(t.stageId, formations[1]);
    end,function()
        logicMgr.ExpeditionMgr.ClearHeroDeadFlag()
    end);

end

function t:ClickClose()
    closeUI(PanelResNames.UIExpeditionStagePreview)
end
return t